<?php

/*

  Action	$4 + 1 potion

  Reveal cards from your deck until you reveal 2 Action cards other than Golem Cards.
  Discard the other cards, then play the Action cards in either order.

 */

class Golem extends Card implements iAction, iKingdom, iAlchemy {

    public function __construct() {
        $price = new Price(4, 1);
        parent::__construct("Golem", $price);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

        public function getDescription() {
        return array(
            "Reveal cards from your deck until you reveal 2 Action cards other than Golem Cards. Discard the other cards, then play the Action cards in either order.");
    }
    public function play(Game $game, $isRealCard) {
        $i = 0;
        $discardCards = array();
        $actionsCards = array();
        while ($i < 2) {
            $card = $game->removeCardFromDrawDeck();
            if (!$card)
                break;
            if ($card instanceof iAction && !$card instanceof Golem) {
                $actionsCards[] = $card;
                $i+=1;
            } else {
                $discardCards[] = $card;
            }
        }
        if (sizeof($actionsCards) == 0) {
             ScreenDisplay::addScreenMessage($game, true, "reveal no actions and discard " . nicePrint($discardCards), "reveals no actions and discards " . ScreenDisplay::$LMSG);
        } else {
             ScreenDisplay::addScreenMessage($game, true, "reveal " . nicePrint($actionsCards) . " and discard " . nicePrint($discardCards), "reveals " . nicePrint($actionsCards) . " and discards " . nicePrint($discardCards));
        }
        $game->discardTempDiscardCards($discardCards);

        if (sizeof($actionsCards) > 0) {

            $output = MySocket::GetUserReply($game, Input_Reorder, $actionsCards, -1, -1, null, "Choose the order to play the actions");
            if (sizeof($output) == 1) {
                 ScreenDisplay::addScreenMessage($game, true, "play " . nicePrint($output[0]), "plays " . ScreenDisplay::$LMSG);
            } else {
                 ScreenDisplay::addScreenMessage($game, true, "play " . nicePrint($output[0]) . " and then " . nicePrint($output[1]), "play " . nicePrint($output[0]) . " and then " . nicePrint($output[1]));
            }
            $output = array_reverse($output);
            foreach ($output as $p) {
                $action_card = n2c($p);
                $game->putCardInPlayArea($p);
                $game->pushCardToStack($action_card);
            }
        }
        $game->cardActionFinished();
        return true;
    }
    
        public function boardSetup(Game $game) {
        $game->addPotion();
        return true;
    }

}

?>